package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user/databases"
	"user/model"

	"user/internal/svc"
	"user/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteUserStarGoodLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteUserStarGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserStarGoodLogic {
	return &DeleteUserStarGoodLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteUserStarGoodLogic) DeleteUserStarGood(in *user.DeleteUserStarGoodRequest) (*user.DeleteUserStarGoodResponse, error) {
	// todo: add your logic here and delete this line
	if in.ID == 0 {
		return &user.DeleteUserStarGoodResponse{}, status.Errorf(codes.InvalidArgument, "id is required")
	}

	info := model.UserStarGood{}
	err := databases.DB.Where("id = ?", in.ID).Delete(&info).Error
	if err != nil {
		return nil, err
	}

	return &user.DeleteUserStarGoodResponse{
		Info: &user.UserStartGood{
			ID:        int64(info.ID),
			GoodSKUID: info.GoodSKUID,
			UserID:    info.UserID,
		},
	}, nil
}
